﻿@model IEnumerable<WSCeCommerce.Domain.Item>
@using WSCeCommerceWeb.Helpers

@{
    ViewBag.Title = "Item List";
    bool allowEdit = SecurityHelper.AlllowManage();
}

<h2 style="text-align:center">Items</h2>

<p style="text-align:center">
    @if (allowEdit) { 
        @Html.ActionLink("Create New", "Create")
    }

</p>
<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Price)
        </th>
       
        @if (!allowEdit)
        {  <th>Add To Cart</th> }
        else
        {  <th>Modify</th> }
        
    </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Price)
            </td>

            <td>
                @if (!allowEdit)
                { <a onclick="AddToCart(@item.ItemId)">Add</a> }
                else
                {
                    @Html.ActionLink("Edit", "Edit", new { id=item.ItemId }) 
                    @Html.ActionLink("Details", "Details", new { id=item.ItemId }) 
                    @Html.ActionLink("Delete", "Delete", new { id=item.ItemId })
                }
                

            </td>

        </tr>
}

</table>
